package com.example.utils;

import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

public class ImageConverter {
    public static void main(String[] args) {
        try {
            // 使用绝对路径，并确保路径正确
            File input = new File("C:/Users/lenovo/Desktop/OCR-demo/Images/question.jpg");

            // 检查文件是否存在
            if (!input.exists()) {
                System.out.println("File not found!");
                return;
            }

            // 读取图片
            BufferedImage image = ImageIO.read(input);

            // 如果读取失败
            if (image == null) {
                System.out.println("Image could not be read!");
                return;
            }

            // 保存为PNG格式
            File output = new File("C:/Users/lenovo/Desktop/OCR-demo/Images/question.png");
            ImageIO.write(image, "png", output);

            System.out.println("Image converted successfully!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
